<?php
namespace Home\Controller;
use Think\Controller;
class HrController extends CommunalController{
	//项目人员管理 designed by:zhangsen 2017-10-18
	function project_user(){
		parent::check_permission('PU');
		if(!empty($_REQUEST['status'])){$status=$_REQUEST['status'];}else{$status=-10;}
		$this->assign('status',$status);
		if(!empty($_REQUEST['fold'])){$fold=$_REQUEST['fold'];}else{$fold=-1;}
		$this->assign('fold',$fold);
		if(!empty($_REQUEST['p_status'])){$p_status=$_REQUEST['p_status'];}else{$p_status=-10;}
		$this->assign('p_status',$p_status);
		if(!empty($_REQUEST['t_day'])){$t_day=$_REQUEST['t_day'];}else{$t_day=date('Y-m-d');}
		$this->assign('t_day',$t_day);
		if(!empty($_REQUEST['nature'])){$nature=$_REQUEST['nature'];}else{$nature=-10;}
		$this->assign('nature',$nature);
		if(!empty($_REQUEST['position'])){$position=$_REQUEST['position'];}else{$position=-10;}
		$this->assign('position',$position);
		if(!empty($_REQUEST['post'])){$post=$_REQUEST['post'];}else{$post=-10;}
		$this->assign('post',$post);
		if(!empty($_REQUEST['rank'])){$rank=$_REQUEST['rank'];}else{$rank=-10;}
		$this->assign('rank',$rank);
		if(!empty($_REQUEST['keyword']))
		{
			$where1="and (db_project.project_num like '%".$_REQUEST['keyword']."%' or db_project.project_name like '%".$_REQUEST['keyword']."%')";
			$where2="and (1=2)";
			$this->assign('keyword',$_REQUEST['keyword']);
		}
		if($p_status!=-10){
			if($p_status==1){
				$where3="and db_project.status=1";
			}elseif($p_status==2){
				$where3="and db_project.status in (-1,-2,-3)";
			}
			$where4="and (1=2)";
		}
		if($status==1){
			$str="(SELECT db_project.project_num,db_project.project_name,db_project.status,db_project_user.pid,db_project_user.uid,db_project_user.nature,db_project_user.come_date FROM `db_project` inner join db_project_user on db_project.id=db_project_user.pid LEFT JOIN db_user on db_project_user.uid=db_user.id WHERE ( db_project.`center_id` = 130005 ) AND (info_id is NULL) AND (('".$t_day."'>=come_date and '".$t_day."'<`out_date`) or ('".$t_day."'>=come_date and out_date is NULL)) and db_user.is_project=1 and db_user.status=1 $where1 $where3 group by pid) ORDER BY project_num desc,come_date desc";	
		}elseif($status==-1){
			$str="(SELECT '' as project_num,'' as project_name,'1' as status,'-10' as pid,'' as uid,'' as nature,'' as come_date from db_user where id in (SELECT uid from db_project_user where come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and db_user.is_project=1 and db_user.status=1 $where2 $where4 group by pid) ORDER BY project_num desc,come_date desc";
		}elseif($status==-2){
			$str="(SELECT '' as project_num,'' as project_name,'1' as status,'-11' as pid,'' as uid,'' as nature,'' as come_date from db_user where id not in(SELECT uid from db_project_user where come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and id not in (SELECT uid from db_project_user where (('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and db_user.is_project=1 and db_user.status=1 $where2 $where4 group by pid) ORDER BY project_num desc,come_date desc";
		}else{
			$str="(SELECT db_project.project_num,db_project.project_name,db_project.status,db_project_user.pid,db_project_user.uid,db_project_user.nature,db_project_user.come_date FROM `db_project` inner join db_project_user on db_project.id=db_project_user.pid LEFT JOIN db_user on db_project_user.uid=db_user.id WHERE ( db_project.`center_id` = 130005 ) AND (info_id is NULL) AND (('".$t_day."'>=come_date and '".$t_day."'<`out_date`) or ('".$t_day."'>=come_date and out_date is NULL)) and db_user.is_project=1 and db_user.status=1 $where1 $where3 group by pid) UNION ALL (SELECT '' as project_num,'' as project_name,'1' as status,'-10' as pid,'' as uid,'' as nature,'' as come_date from db_user where id in (SELECT uid from db_project_user where come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and db_user.is_project=1 and db_user.status=1 $where2 $where4 group by pid)  UNION ALL (SELECT '' as project_num,'' as project_name,'1' as status,'-11' as pid,'' as uid,'' as nature,'' as come_date from db_user where id not in(SELECT uid from db_project_user where come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and id not in (SELECT uid from db_project_user where (('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and db_user.is_project=1 and db_user.status=1 $where2 $where4 group by pid)  ORDER BY project_num desc,come_date desc";	
		}
		$Model=M();
		$result=$Model->query($str);
		//详情
		$db_project_user=M('db_project_user');
		$db_user=M('db_user');
		foreach($result as $key=>$value){
			if($value['pid']==-10){
				$where_f['is_project']=1;
				$where_f['db_user.status']=1;
				$where_f['_string']="come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))";
				$result[$key]['detail']=$db_project_user->join('left join db_user on db_project_user.uid=db_user.id')->join('left join db_universal_label2 on db_universal_label2.id=db_project_user.post')->where($where_f)->order("db_universal_label2.second_sort")->select();
			}elseif($value['pid']==-11){
				$where_f['db_user.status']=1;
				$where_f['_string']="id not in(SELECT uid from db_project_user where come_date>'".$t_day."' and uid not in (select uid from db_project_user where ('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and id not in (SELECT uid from db_project_user where (('".$t_day."'>=come_date and '".$t_day."'<`out_date` and pid is not NULL) or ('".$t_day."'>=come_date and out_date is NULL and pid is not NULL))) and db_user.is_project=1 ";
				$result[$key]['detail']=$db_user->field('db_user.id as uid,position_id,rank_id,position_descr as position,rank_descr as rank')->where($where_f)->order('position_id in (298,297,299,301,286,303,335,336,296,283,313,280,305,306,304,300,337)')->select();
				foreach($result[$key]['detail'] as $kk=>$vv){
					//$result[$key]['detail'][$kk]['position']=$this->get_db_universal_label(2,$vv['position_id']);
					//$result[$key]['detail'][$kk]['rank']=$this->get_db_universal_label(2,$vv['rank_id']);
				}
			}else{
				$where_u['pid']=$value['pid'];
				$where_u['_string']="(('".$t_day."'>=come_date and '".$t_day."'<`out_date`) or ('".$t_day."'>=come_date and out_date is NULL))";
				$where_u['is_project']=1;
				$where_u['db_user.status']=1;
				$result[$key]['detail']=$db_project_user->join('left join db_user on db_project_user.uid=db_user.id')->join('left join db_universal_label2 on db_universal_label2.id=db_project_user.post')->where($where_u)->order("db_universal_label2.second_sort")->select();
			}
			foreach($result[$key]['detail'] as $k=>$v){
                $result6[]=$v['position'];
				$user=$this->get_user($v['uid']);
				$result[$key]['detail'][$k]['username']=$user['username'];
				$result[$key]['detail'][$k]['mobilephone']=$user['mobilephone'];
				if($nature!=-10){
					if($nature=='无'){$nature='';}
					if($result[$key]['detail'][$k]['nature']!=$nature){
						unset($result[$key]['detail'][$k]);continue;
					}
				}
				if($position!=-10){
					if($v['position']!=$position){
						unset($result[$key]['detail'][$k]);continue;
					}
				}
				if($post!=-10){
					if(!empty($v['post'])){
						if($v['post']!=$post){
							unset($result[$key]['detail'][$k]);continue;
						}else{
                            $db_universal_label2=M('db_universal_label2');
                            $post_where['id']=$v['post'];
                            $post_name=$db_universal_label2->where($post_where)->find();
                            $result[$key]['detail'][$k]['post']=$post_name['second_name'];
                        }
					}else{
						if($v['position']!=$post){
							unset($result[$key]['detail'][$k]);continue;
						}
					}
				}else{
                    $db_universal_label2=M('db_universal_label2');
                    $post_where['id']=$v['post'];
                    $post_name=$db_universal_label2->where($post_where)->find();
                    $result[$key]['detail'][$k]['post']=$post_name['second_name'];
                }
				if($rank!=-10){
					if($v['rank']!=$rank){
						unset($result[$key]['detail'][$k]);continue;
					}
				}
			}
			$result[$key]['sum']=count($result[$key]['detail']);
			if(empty($result[$key]['detail'])){
				unset($result[$key]);
			}
		}
		//职位下拉菜单
		$db_universal_label2=M('db_universal_label2');
		$where_s['first_id']=106;
		$position=$db_universal_label2->field('id,second_name')->where($where_s)->order("second_sort")->select();
		$this->assign('result4',$position);
		$result6=array_unique($result6);
		//职级下拉菜单
		$rank=$this->library_type_list(8);
		$this->assign('result5',$rank[0]['second']);
		$this->assign('result6',$result6);
		$this->assign('result',$result);
		$this->assign('page',$show);
		$this->display();
	}
	
	//项目人员管理->编辑项目人员工作情况 designed by:zhangsen 2017-10-18
	function project_user_edit(){
		parent::check_permission('PU',NULL,1);
		//职位下拉菜单
		$db_universal_label2=M('db_universal_label2');
		$where_s['first_id']=106;
		$position=$db_universal_label2->field('id,second_name')->where($where_s)->order("second_sort")->select();
		$this->assign('result4',$position);
		//职级下拉菜单
		$rank=$this->library_type_list(8);
		$this->assign('result5',$rank[0]['second']);
		$user=$this->get_user($_REQUEST['uid']);
		$db_project_user=M('db_project_user');
		$where['uid']=$_REQUEST['uid'];
		$result=$db_project_user->where($where)->order('come_date desc')->select();
		foreach($result as $key=>$value){
			$project=NULL;
			if(!empty($value['pid'])){
				$project=$this->get_project($value['pid']);
				$result[$key]['project_num']=$project['project_num'];
				$result[$key]['project_name']=$project['project_name'];
			}
			$result[$key]['status']=$project['status']?$project['status']:1;
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
            $db_universal_label2=M('db_universal_label2');
            $post_where['id']=$value['post'];
            $post_name=$db_universal_label2->where($post_where)->find();
            $result[$key]['post_name']=$post_name['second_name'];
		}
		//项目数据
		$db_project=M('db_project');
		$where_p['center_id']=130005;
		$where_p['status']=1;
		$where_p['info_id']=array('exp','IS NULL');
		$project_list=$db_project->where($where_p)->order('status desc,add_date desc')->select();
		$this->assign('project_list',$project_list);
		$this->assign('result',$result);
		$this->assign('user',$user);
		//编辑提交
		if($_REQUEST['action']=='edit')
		{
			$user=$this->get_user($_REQUEST['uid']);
			$db_user=M('db_user');
			//判断手机号是否重复
			if(!empty($_REQUEST['mobilephone'])){
				$where_phone['mobilephone']=$_REQUEST['mobilephone'];
				$phone_list=$db_user->where($where_phone)->find();
				if(!empty($phone_list) && ($phone_list['id']!=$_REQUEST['uid']))
				{
					$this->error("该手机号已存在！");die;
				}
			}
			//编辑
			$where_edit['id']=$_REQUEST['uid'];
			//$where_edit['mobilephone']=$_REQUEST['mobilephone'];
			//$where_edit['position_id']=$_REQUEST['position_id'];
			//$where_edit['rank_id']=$_REQUEST['rank_id'];
			//附件
			if($_REQUEST['file_url']){
				//判断是否修改过文件
				if($_REQUEST['file_url']!=$user['file_url']){
					$where_edit['file_url']=$_REQUEST['file_url'];
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$user['file_url']);
					if (file_exists($file1)){
						@unlink($file1);
					}
				}
			}else{
				$where_edit['file_url']=NULL;
				if($user['file_url']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$user['file_url']);
					if (file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			$where_edit['file_name']=$_REQUEST['file_name']?$_REQUEST['file_name']:NULL;
			$db_user->save($where_edit);
			//项目人员表
			$where_d['uid']=$_REQUEST['uid'];
			$db_project_user->where($where_d)->delete();
			foreach($_REQUEST['project_name_copy'] as $key=>$value){
				$where_u['uid']=$_REQUEST['uid'];
				$where_u['pid']=$value?$value:NULL;
				$where_u['position']=$_REQUEST['position_descr'];
				$where_u['rank']=$_REQUEST['rank_copy'][$key];
				$where_u['post']=$_REQUEST['post_copy'][$key];
				$where_u['nature']=$_REQUEST['nature_copy'][$key];
				$where_u['come_date']=$_REQUEST['come_date_copy'][$key];
				$where_u['out_date']=$_REQUEST['out_date_copy'][$key]?$_REQUEST['out_date_copy'][$key]:NULL;
				$where_u['add_uid']=$this->login_id;
				$where_u['add_date']=date("Y-m-d H:i:s");
				$db_project_user->add($where_u);
			}
			$this->success("操作成功",__APP__."/Hr/project_user_edit/keyword/".$_REQUEST['keyword']."/status/".$_REQUEST['status']."/fold/".$_REQUEST['fold']."/position/".$_REQUEST['position_s']."/rank/".$_REQUEST['rank_s']."/nature/".$_REQUEST['nature_s']."/uid/".$_REQUEST['uid']."&p=".$_SESSION['page']);die;
		}
		$this->assign('uid',$_REQUEST['uid']);
		$this->assign('status',$_REQUEST['status']);
		$this->assign('position',$_REQUEST['position']);
		$this->assign('rank',$_REQUEST['rank']);
		$this->assign('nature',$_REQUEST['nature']);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('fold',$_REQUEST['fold']);
		$this->assign('p_status',$_REQUEST['p_status']);
		$this->assign('t_day',$_REQUEST['t_day']);
		$this->display();
	}
	
	//项目人员管理->项目人员工作情况 designed by:zhangsen 2017-10-18
	function project_user_detail_u(){
		parent::check_permission('PU');
		$user=$this->get_user($_REQUEST['uid']);
		$user['position']=$this->get_db_universal_label(2,$user['position_id']);
		$user['rank']=$this->get_db_universal_label(2,$user['rank_id']);
		$db_project_user=M('db_project_user');
		$where['uid']=$_REQUEST['uid'];
		$result=$db_project_user->where($where)->order('come_date desc')->select();
		foreach($result as $key=>$value){
			if(!empty($value['pid'])){
				$project=$this->get_project($value['pid']);
				$result[$key]['project_num']=$project['project_num'];
				$result[$key]['project_name']=$project['project_name'];
			}
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
            $db_universal_label2=M('db_universal_label2');
            $post_where['id']=$value['post'];
            $post_name=$db_universal_label2->where($post_where)->find();
            $result[$key]['post']=$post_name['second_name'];
		}
		$this->assign('result',$result);
		$this->assign('user',$user);
		$this->display();
	}
	
	//项目人员管理->项目人员情况 designed by:zhangsen 2017-10-18
	function project_user_detail_p(){
		parent::check_permission('PU');
		$project=$this->get_project($_REQUEST['pid']);
		$result_type=$this->get_db_universal_type(4,1,NULL,null,NULL,$project['status']);
		$project['status_name']=$result_type['name1'];
		$db_project_user=M('db_project_user');
		$where['pid']=$_REQUEST['pid'];
		$result=$db_project_user->where($where)->order('come_date desc')->select();
		foreach($result as $key=>$value){
			$user=$this->get_user($value['uid']);
			$result[$key]['username']=$user['username'];
			$result[$key]['u_status']=$user['status'];
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
            $db_universal_label2=M('db_universal_label2');
            $post_where['id']=$value['post'];
            $post_name=$db_universal_label2->where($post_where)->find();
            $result[$key]['post']=$post_name['second_name'];
		}
		$this->assign('result',$result);
		$this->assign('project',$project);
		$this->display();
	}

    //项目人员管理->项目职务管理 designed by:wuhuili 2018-06-22
    function project_user_position(){
        $db_universal_label1=M('db_universal_label1');
        $db_universal_label2=M('db_universal_label2');
        $where_first['classif']=23;
        $where_first['first_name']=array('exp','is not NULL');
        $result=$db_universal_label1->field('id,first_name,classif')->where($where_first)->order('classif,first_sort')->select();

        foreach($result as $key=>$val){
            $where_second['first_id']=$val['id'];
            $where_second['second_name']=array('neq','全部');
            $result[$key]['second']=$db_universal_label2->field('id,second_name')->where($where_second)->order('second_sort')->select();
            $result[$key]['sum']=$db_universal_label2->field('id,second_name')->where($where_second)->order('second_sort')->count();
            //二级循环
            foreach($result[$key]['second'] as $kk=>$vv){
                $db_project_user=M('db_project_user');
                $user_where['post']=$vv['id'];
                $count=$db_project_user->where($user_where)->count();
                if($count>0){
                    $result[$key]['second'][$kk]['is_delete']=1;
                }else{
                    $result[$key]['second'][$kk]['is_delete']=2;
                }
            }
        }
        $this->assign('result',$result);
        $this->assign('classif',23);
        $this->display();
    }
	
	//绩效考评 designed by:zhaoshihao 2018-01-11
	function jixiao_personal(){
		parent::check_permission('KP');
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		if(!empty($_REQUEST['msum'])){$msum=$_REQUEST['msum'];}else{$msum=-1;}
		$this->assign('msum',$msum);
		if(!empty($_REQUEST['uid'])){$uid=$_REQUEST['uid'];}else{$uid=-10;}
		$this->assign('uid',$uid);
		$this->assign('list',$this->get_db_universal_type(99));
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		$where['year_type']=20172;
		if($type!=-10){$where['appraisal_type']=$type;}
		if($uid!=-10){$where['uid']=$uid;}
		$result=$db_jixiao_join->where($where)->order('center,department')->select();
		foreach($result as $key=>$value){
			$result[$key]['center_name']=$this->get_oa_dep_name($value['center']);
			$result[$key]['department_name']=$this->get_db_universal_label(2,$value['department']);
			if(!empty($value['sup_uid3'])){$result[$key]['sup3']=1;}
			foreach(explode(",",$value['zhanbi']) as $kk=>$vv){
				$bl[($kk+1)]=$vv;
			}
			$result[$key]['bl1']=$bl[1];
			$result[$key]['bl2']=$bl[2];
			$result[$key]['bl3']=$bl[3];
			$result[$key]['bl4']=$bl[4];
			//领导考评
			$where_1['uid']=$value['uid'];
			$where_1['status']=1;
			$where_1['able']=1;
			$where_1['standard']=$value['standard1'];
			$where_1['year_type']=20172;
			$result[$key]['sum1']=$db_jixiao_appraisal->where($where_1)->Avg('sum_all')+0;
			$sum1_p=explode(",",$value['sup_uid1']);
			$s1_yp=$db_jixiao_appraisal->field('add_uid')->where($where_1)->select();
			$sum1_y=array();
			$yp1=array();
			foreach($s1_yp as $k1=>$v1){
				$sum1_y[]=$v1['add_uid'];
			}
			foreach($sum1_p as $kk=>$vv){
				foreach($sum1_y as $kkk=>$vvv){
					if($vv==$vvv){
						$yp1[]=$vv;
						unset($sum1_p[$kk]);
					}
				}
			}
			$yp11=array();
			$wp1=array();
			foreach($yp1 as $a1=>$b1){
				$where_y1['uid']=$value['uid'];
				$where_y1['status']=1;
				$where_y1['able']=1;
				$where_y1['standard']=$value['standard1'];
				$where_y1['year_type']=20172;
				$where_y1['add_uid']=$b1;
				$yp1s=$db_jixiao_appraisal->where($where_y1)->find();
				$yp11[]=$this->get_username($b1).':'.$yp1s['sum_all'];
			}
			foreach($sum1_p as $c1=>$d1){
				$wp1[]=$this->get_username($d1);
			}
			$result[$key]['sum1_yp']=join(',',$yp11);
			$result[$key]['sum1_wp']=join(',',$wp1);
			//360考评
			$where_2['uid']=$value['uid'];
			$where_2['status']=1;
			$where_2['able']=1;
			$where_2['standard']=$value['standard2'];
			$where_2['year_type']=20172;
			if($msum==1){$where_2['sum_all']=array('neq',100);}
			$result[$key]['sum2']=round($db_jixiao_appraisal->where($where_2)->Avg('sum_all')+0,2);
			$sum2_p=explode(",",$value['sup_uid2']);
			unset($where_2['sum_all']);
			$s2_yp=$db_jixiao_appraisal->field('add_uid')->where($where_2)->select();
			$sum2_y=array();
			$yp2=array();
			foreach($s2_yp as $k2=>$v2){
				$sum2_y[]=$v2['add_uid'];
			}
			foreach($sum2_p as $kk2=>$vv2){
				foreach($sum2_y as $kkk2=>$vvv2){
					if($vv2==$vvv2){
						$yp2[]=$vv2;
						unset($sum2_p[$kk2]);
					}
				}
			}
			$yp22=array();
			$wp2=array();
			foreach($yp2 as $a2=>$b2){
				$where_y2['uid']=$value['uid'];
				$where_y2['status']=1;
				$where_y2['able']=1;
				$where_y2['standard']=$value['standard2'];
				$where_y2['year_type']=20172;
				$where_y2['add_uid']=$b2;
				$yp2s=$db_jixiao_appraisal->where($where_y2)->find();
				$yp22[]=$this->get_username($b2).':'.$yp2s['sum_all'];
			}
			foreach($sum2_p as $c2=>$d2){
				$wp2[]=$this->get_username($d2);
			}
			$result[$key]['sum2_yp']=join(',',$yp22);
			$result[$key]['sum2_wp']=join(',',$wp2);
			//PBC
			$result[$key]['sum3']=$value['sup_uid3_sum'];
			//述职
			$result[$key]['sum4']=$value['sup_uid4_sum'];
			$result[$key]['sum']=round(($result[$key]['sum1']*$bl[1]+$result[$key]['sum2']*$bl[2]+$result[$key]['sum3']*$bl[3]+$result[$key]['sum4']*$bl[4])*0.01,2);
		}
		unset($where['uid']);
		$user=$db_jixiao_join->field('uid,username')->where($where)->order('id desc')->select();
		$this->assign("user",$user);
		$this->assign("result",$result);
		$this->display();
	}
	//绩效考评 designed by:zhaoshihao 2018-01-11
	function jixiao_personal1(){
		parent::check_permission('KP');
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		if(!empty($_REQUEST['msum'])){$msum=$_REQUEST['msum'];}else{$msum=-1;}
		$this->assign('msum',$msum);
		if(!empty($_REQUEST['uid'])){$uid=$_REQUEST['uid'];}else{$uid=-10;}
		$this->assign('uid',$uid);
		$this->assign('list',$this->get_db_universal_type(99));
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		$where['year_type']=20172;
		if($type!=-10){$where['appraisal_type']=$type;}
		if($uid!=-10){$where['uid']=$uid;}
		$result=$db_jixiao_join->where($where)->order('center,department')->select();
		foreach($result as $key=>$value){
			$result[$key]['center_name']=$this->get_oa_dep_name($value['center']);
			$result[$key]['department_name']=$this->get_db_universal_label(2,$value['department']);
			if(!empty($value['sup_uid3'])){$result[$key]['sup3']=1;}
			foreach(explode(",",$value['zhanbi']) as $kk=>$vv){
				$bl[($kk+1)]=$vv;
			}
			$result[$key]['bl1']=$bl[1];
			$result[$key]['bl2']=$bl[2];
			$result[$key]['bl3']=$bl[3];
			$result[$key]['bl4']=$bl[4];
			//领导考评
			$where_1['uid']=$value['uid'];
			$where_1['status']=1;
			$where_1['able']=1;
			$where_1['standard']=$value['standard1'];
			$where_1['year_type']=20172;
			$result[$key]['sum1']=$db_jixiao_appraisal->where($where_1)->Avg('sum_all')+0;
			$sum1_p=explode(",",$value['sup_uid1']);
			$s1_yp=$db_jixiao_appraisal->field('add_uid')->where($where_1)->select();
			$sum1_y=array();
			$yp1=array();
			foreach($s1_yp as $k1=>$v1){
				$sum1_y[]=$v1['add_uid'];
			}
			foreach($sum1_p as $kk=>$vv){
				foreach($sum1_y as $kkk=>$vvv){
					if($vv==$vvv){
						$yp1[]=$vv;
						unset($sum1_p[$kk]);
					}
				}
			}
			$yp11=array();
			$wp1=array();
			foreach($yp1 as $a1=>$b1){
				$where_y1['uid']=$value['uid'];
				$where_y1['status']=1;
				$where_y1['able']=1;
				$where_y1['standard']=$value['standard1'];
				$where_y1['year_type']=20172;
				$where_y1['add_uid']=$b1;
				$yp1s=$db_jixiao_appraisal->where($where_y1)->find();
				$yp11[]=$this->get_username($b1).':'.$yp1s['sum_all'];
			}
			foreach($sum1_p as $c1=>$d1){
				$wp1[]=$this->get_username($d1);
			}
			$result[$key]['sum1_yp']=join(',',$yp11);
			$result[$key]['sum1_wp']=join(',',$wp1);
			//360考评
			$where_2['uid']=$value['uid'];
			$where_2['status']=1;
			$where_2['able']=1;
			$where_2['standard']=$value['standard2'];
			$where_2['year_type']=20172;
			if($msum==1){$where_2['sum_all']=array('neq',100);}
			$result[$key]['sum2']=round($db_jixiao_appraisal->where($where_2)->Avg('sum_all')+0,2);
			$sum2_p=explode(",",$value['sup_uid2']);
			unset($where_2['sum_all']);
			$s2_yp=$db_jixiao_appraisal->field('add_uid')->where($where_2)->select();
			$sum2_y=array();
			$yp2=array();
			foreach($s2_yp as $k2=>$v2){
				$sum2_y[]=$v2['add_uid'];
			}
			foreach($sum2_p as $kk2=>$vv2){
				foreach($sum2_y as $kkk2=>$vvv2){
					if($vv2==$vvv2){
						$yp2[]=$vv2;
						unset($sum2_p[$kk2]);
					}
				}
			}
			$yp22=array();
			$wp2=array();
			foreach($yp2 as $a2=>$b2){
				$where_y2['uid']=$value['uid'];
				$where_y2['status']=1;
				$where_y2['able']=1;
				$where_y2['standard']=$value['standard2'];
				$where_y2['year_type']=20172;
				$where_y2['add_uid']=$b2;
				$yp2s=$db_jixiao_appraisal->where($where_y2)->find();
				$yp22[]=$this->get_username($b2).':'.$yp2s['sum_all'];
			}
			foreach($sum2_p as $c2=>$d2){
				$wp2[]=$this->get_username($d2);
			}
			$result[$key]['sum2_yp']=join(',',$yp22);
			$result[$key]['sum2_wp']=join(',',$wp2);
			//PBC
			$result[$key]['sum3']=$value['sup_uid3_sum'];
			//述职
			$result[$key]['sum4']=$value['sup_uid4_sum'];
			$result[$key]['sum']=round(($result[$key]['sum1']*$bl[1]+$result[$key]['sum2']*$bl[2]+$result[$key]['sum3']*$bl[3]+$result[$key]['sum4']*$bl[4])*0.01,2);
		}
		unset($where['uid']);
		$user=$db_jixiao_join->field('uid,username')->where($where)->order('id desc')->select();
		$this->assign("user",$user);
		$this->assign("result",$result);
		$this->display();
	}
	//绩效考评 designed by:zhaoshihao 2018-01-11
	function jixiao_personal_ajax(){
		$db_jixiao_join=M('db_jixiao_join');
		$where['id']=$_REQUEST['id'];
		if($_REQUEST['action']=='three'){
			$where['sup_uid3_sum']=$_REQUEST['sum'];
		}else{
			$where['sup_uid4_sum']=$_REQUEST['sum'];
		}
		$db_jixiao_join->save($where);
		$data['status']=self::YES;
		echo json_encode($data);die;
	}
	
	//考评人员 designed by:zhaoshihao 2018-01-11
	function jixiao_user(){
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		if(!empty($_REQUEST['uid'])){$uid=$_REQUEST['uid'];}else{$uid=-10;}
		$this->assign('uid',$uid);
		$this->assign('list',$this->get_db_universal_type(99));
		$db_jixiao_appraisal=M('db_jixiao_appraisal');
		$db_jixiao_form=M('db_jixiao_form');
		$db_jixiao_join=M('db_jixiao_join');
		$where['year_type']=20172;
		if($type!=-10){$where['appraisal_type']=$type;}
		if($uid!=-10){$where['uid']=$uid;}
		$result=$db_jixiao_join->where($where)->order('center,department')->select();
		foreach($result as $key=>$value){
			$result[$key]['center_name']=$this->get_oa_dep_name($value['center']);
			$result[$key]['department_name']=$this->get_db_universal_label(2,$value['department']);
			//领导考评
			$where_1['uid']=$value['uid'];
			$where_1['status']=1;
			$where_1['able']=1;
			$where_1['standard']=$value['standard1'];
			$where_1['year_type']=20172;
			$sum1_p=explode(",",$value['sup_uid1']);
			$s1_yp=$db_jixiao_appraisal->field('add_uid')->where($where_1)->select();
			$sum1_y=array();
			$yp1=array();
			foreach($s1_yp as $k1=>$v1){
				$sum1_y[]=$v1['add_uid'];
			}
			foreach($sum1_p as $kk=>$vv){
				foreach($sum1_y as $kkk=>$vvv){
					if($vv==$vvv){
						$yp1[]=$vv;
						unset($sum1_p[$kk]);
					}
				}
			}
			$yp11=array();
			$wp1=array();
			foreach($yp1 as $a1=>$b1){
				$where_y1['uid']=$value['uid'];
				$where_y1['status']=1;
				$where_y1['able']=1;
				$where_y1['standard']=$value['standard1'];
				$where_y1['year_type']=20172;
				$where_y1['add_uid']=$b1;
				$yp1s=$db_jixiao_appraisal->where($where_y1)->find();
				$yp1s['sum_all']=$yp1s['sum_all']+0;
				$yp11[]="<a href=".__APP__."/Index/jixiao_detail/id/".$yp1s['id']."/sta/1>".$this->get_username($b1).':'.$yp1s['sum_all']."分</a>";
			}
			foreach($sum1_p as $c1=>$d1){
				$wp1[]=$this->get_username($d1);
			}
			$result[$key]['sum1_yp']=join(',',$yp11);
			$result[$key]['sum1_wp']=join(',',$wp1);
			//360考评
			$where_2['uid']=$value['uid'];
			$where_2['_string']="(status=1) or (able=-1)";
			$where_2['standard']=$value['standard2'];
			$where_2['year_type']=20172;
			$sum2_p=explode(",",$value['sup_uid2']);
			$s2_yp=$db_jixiao_appraisal->field('add_uid')->where($where_2)->select();
			$sum2_y=array();
			$yp2=array();
			foreach($s2_yp as $k2=>$v2){
				$sum2_y[]=$v2['add_uid'];
			}
			foreach($sum2_p as $kk2=>$vv2){
				foreach($sum2_y as $kkk2=>$vvv2){
					if($vv2==$vvv2){
						$yp2[]=$vv2;
						unset($sum2_p[$kk2]);
					}
				}
			}
			$yp22=array();
			$wp2=array();
			foreach($yp2 as $a2=>$b2){
				$where_y2['uid']=$value['uid'];
				$where_y2['_string']="(status=1) or (able=-1)";
				$where_y2['standard']=$value['standard2'];
				$where_y2['year_type']=20172;
				$where_y2['add_uid']=$b2;
				$yp2s=$db_jixiao_appraisal->where($where_y2)->find();
				if($yp2s['able']==-1){
					$yp22[]="<span style='color:#666'>".$this->get_username($b2).":弃权</span>";
				}else{
					$yp2s['sum_all']=$yp2s['sum_all']+0;
					$yp22[]="<a href=".__APP__."/Index/jixiao_detail/id/".$yp2s['id']."/sta/2>".$this->get_username($b2).':'.$yp2s['sum_all']."分</a>";
				}
			}
			foreach($sum2_p as $c2=>$d2){
				$wp2[]=$this->get_username($d2);
			}
			$result[$key]['sum2_yp']=join(',',$yp22);
			$result[$key]['sum2_wp']=join(',',$wp2);
		}
		unset($where['uid']);
		$user=$db_jixiao_join->field('uid,username')->where($where)->order('id desc')->select();
		$this->assign("user",$user);
		$this->assign("result",$result);
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc(){
		if(!empty($_REQUEST['cid'])){$cid=$_REQUEST['cid'];}else{$cid=-10;}
		$this->assign('cid',$cid);
		//指标类型筛选
		$this->assign('cids',$this->get_db_universal_type(17));
		//添加指标类型筛选
		$this->assign('cids_list',$this->get_db_universal_type(17,NULL,NULL,1));
		$db_jixiao_pbc=M('db_jixiao_pbc');
		if($cid!=-10){$where['cid']=$cid;}
		$where['type']=1;
		$result=$db_jixiao_pbc->where($where)->order('add_date asc,id asc')->select();
		$this->assign("result",$result);
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc_position(){
		if(!empty($_REQUEST['p_id'])){$p_id=$_REQUEST['p_id'];}else{$p_id=-10;}
		$this->assign('p_id',$p_id);
		//指标类型筛选
		$this->assign('cids_list',$this->get_db_universal_type(17,NULL,NULL,1));
		if($p_id!=-10){
			$db_jixiao_pbc=M('db_jixiao_pbc');
			$where['p_id']=$p_id;
			$where['type']=2;
			$result=$db_jixiao_pbc->where($where)->group('cid')->select();
			$sum_w=NULL;
			foreach($result as $key=>$value){
				$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
				$result[$key]['cname']=$type_list['name2'];	
				$where['cid']=$value['cid'];
				$where['p_id']=$p_id;
				$where['type']=2;
				$result_d=$db_jixiao_pbc->where($where)->order('add_date asc,id asc')->select();
				foreach($result_d as $kk=>$vv){
					if($vv['cid']!=5){
						$sum_w+=$vv['weight'];
					}
				}
				$result[$key]['detail']=$result_d;
				$result[$key]['sum']=count($result_d);
			}
			$this->assign("sum_w",$sum_w);
			$this->assign("result",$result);
		}
		//职位下拉
		$db_user=M('db_user');
		$where_4['position_descr']=array('exp','IS NOT NULL');
		$result_position=$db_user->field('position_id,position_descr')->where($where_4)->group('position_id')->order('position_id')->select();
		$this->assign('result_position',$result_position);
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc_user(){
		if(!empty($_REQUEST['u_id'])){$u_id=$_REQUEST['u_id'];}else{$u_id=-10;}
		$this->assign('u_id',$u_id);
		//指标类型筛选
		$this->assign('cids_list',$this->get_db_universal_type(17,NULL,NULL,1));
		if($u_id!=-10){
			$db_jixiao_pbc=M('db_jixiao_pbc');
			$db_jixiao_pbc_user=M('db_jixiao_pbc_user');
			$where['u_id']=$u_id;
			$where['type']=3;
			$result=$db_jixiao_pbc->where($where)->group('cid')->select();
			$status=-1;
			$sum_w=NULL;$sum_t1=NULL;$sum_t2=NULL;$sum_t3=NULL;$sum_c_value=NULL;$sum_score=NULL;
			if(empty($result)){
				$user=$this->get_user($u_id);
				$where_p['p_id']=$user['position_id'];
				$where_p['type']=2;
				$result=$db_jixiao_pbc->where($where_p)->group('cid')->select();
				foreach($result as $key=>$value){
					$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
					$result[$key]['cname']=$type_list['name2'];	
					$where_d['cid']=$value['cid'];
					$where_d['p_id']=$user['position_id'];
					$where_d['type']=2;
					$result_d=$db_jixiao_pbc->where($where_d)->order('add_date asc,id asc')->select();
					foreach($result_d as $kk=>$vv){
						$where_u['m_id']=$vv['id'];
						$result_u=$db_jixiao_pbc_user->where($where_u)->find();
						$this->assign("out_uid",$result_u['out_uid']);
						$this->assign("out_name",$this->get_user($result_u['out_uid']));
						$this->assign("ht_sdate",$result_u['ht_sdate']);
						$this->assign("ht_edate",$result_u['ht_edate']);
						$this->assign("qy_date",$result_u['qy_date']);
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
						if($result_u['status']==1){
							$status=1;
						}
						if($vv['cid']!=5){
							$sum_w+=$vv['weight'];
						}
						$sum_t1+=$result_u['t1'];
						$sum_t2+=$result_u['t2'];
						$sum_t3+=$result_u['t3'];
						$sum_c_value+=$result_u['c_value'];
						$sum_score+=$result_u['score'];
					}
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}else{
				foreach($result as $key=>$value){
					$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
					$result[$key]['cname']=$type_list['name2'];	
					$where_d['cid']=$value['cid'];
					$where_d['u_id']=$u_id;
					$where_d['type']=3;
					$result_d=$db_jixiao_pbc->where($where_d)->order('add_date asc,id asc')->select();
					foreach($result_d as $kk=>$vv){
						$where_u['m_id']=$vv['id'];
						$result_u=$db_jixiao_pbc_user->where($where_u)->find();
						$this->assign("out_uid",$result_u['out_uid']);
						$this->assign("out_name",$this->get_user($result_u['out_uid']));
						$this->assign("ht_sdate",$result_u['ht_sdate']);
						$this->assign("ht_edate",$result_u['ht_edate']);
						$this->assign("qy_date",$result_u['qy_date']);
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
						if($result_u['status']==1){
							$status=1;
						}
						if($vv['cid']!=5){
							$sum_w+=$vv['weight'];
						}
						$sum_t1+=$result_u['t1'];
						$sum_t2+=$result_u['t2'];
						$sum_t3+=$result_u['t3'];
						$sum_c_value+=$result_u['c_value'];
						$sum_score+=$result_u['score'];
					}
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}
			$this->assign("sum_w",$sum_w?$sum_w:NULL);
			$this->assign("sum_t1",$sum_t1?$sum_t1:NULL);
			$this->assign("sum_t2",$sum_t2?$sum_t2:NULL);
			$this->assign("sum_t3",$sum_t3?$sum_t3:NULL);
			$this->assign("sum_c_value",$sum_c_value?$sum_c_value:NULL);
			$this->assign("sum_score",$sum_score?$sum_score:NULL);
			$this->assign("status",$status);
			$this->assign("result",$result);
		}
		//姓名下拉菜单
		$this->assign('ht_sdate',date('Y')."-01-01");
		$this->assign('ht_edate',date('Y')."-12-31");
		$this->assign('result1',$this->get_all_username());
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc_view(){
		if(!empty($_REQUEST['u_id'])){$u_id=$_REQUEST['u_id'];}else{$u_id=-10;}
		$this->assign('u_id',$u_id);
		$db_user=M('db_user');
		$db_jixiao_pbc_user=M('db_jixiao_pbc_user');
		$db_universal_label2=M('db_universal_label2');
		if($u_id!=-10){$where['id']=$u_id;}
		$where['username']=array('neq','admin');
		$where['status']=1;
		$count=$db_user->where($where)->count();
		$Page = new \Think\Page($count,15);
		$show=$Page->show();
		$result=$db_user->where($where)->order('add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($result as $key=>$value){
			$name_p_str=NULL;
			$where_u['u_id']=$value['id'];
			$where_u['status']=1;
			$result_u=$db_jixiao_pbc_user->where($where_u)->find();
			$result[$key]['ht_sdate']=$result_u['ht_sdate'];
			$result[$key]['ht_edate']=$result_u['ht_edate'];
			$result[$key]['qy_date']=$result_u['qy_date'];
			$user=$this->get_user($result_u['out_uid']);
			$result[$key]['out_name']=$user['username'];
			//职位
			$where_p['id']=array('in',$value['position_id']);
			$name_p=$db_universal_label2->where($where_p)->select();
			foreach($name_p as $kk=>$vv)
			{
				$name_p_str.=$vv['second_name'].',';
			}
			$result[$key]['position']=rtrim($name_p_str,',');
		}
		$this->assign('page',$show);
		$this->assign("result",$result);
		$this->assign('result1',$this->get_all_username());
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc_view_detail(){
		if(!empty($_REQUEST['u_id'])){$u_id=$_REQUEST['u_id'];}else{$u_id=-10;}
		$this->assign('u_id',$u_id);
		$user=$this->get_user($u_id);
		$this->assign('u_name',$user['username']);
		//指标类型筛选
		$this->assign('cids_list',$this->get_db_universal_type(17,NULL,NULL,1));
		$db_jixiao_pbc=M('db_jixiao_pbc');
		$db_jixiao_pbc_user=M('db_jixiao_pbc_user');
		$where['u_id']=$u_id;
		$where['type']=3;
		$result=$db_jixiao_pbc->where($where)->group('cid')->select();
		$sum_w=NULL;
		if(empty($result)){
			$where_p['p_id']=$user['position_id'];
			$where_p['type']=2;
			$result=$db_jixiao_pbc->where($where_p)->group('cid')->select();
			foreach($result as $key=>$value){
				$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
				$result[$key]['cname']=$type_list['name2'];	
				$where_d['cid']=$value['cid'];
				$where_d['p_id']=$user['position_id'];
				$where_d['type']=2;
				$result_d=$db_jixiao_pbc->where($where_d)->select();
				foreach($result_d as $kk=>$vv){
					$where_u['m_id']=$vv['id'];
					$where_u['status']=1;
					$result_u=$db_jixiao_pbc_user->where($where_u)->find();
					if($result_u){
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
						if($vv['cid']!=5){
							$sum_w+=$vv['weight'];
						}
						$sum_t1+=$result_u['t1'];
						$sum_t2+=$result_u['t2'];
						$sum_t3+=$result_u['t3'];
						$sum_c_value+=$result_u['c_value'];
						$sum_score+=$result_u['score'];
						$this->assign("out_uid",$result_u['out_uid']);
						$this->assign("out_name",$this->get_user($result_u['out_uid']));
						$this->assign("ht_sdate",$result_u['ht_sdate']);
						$this->assign("ht_edate",$result_u['ht_edate']);
						$this->assign("qy_date",$result_u['qy_date']);
					}else{
						unset($result);
					}
				}
				if($result){
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}
		}else{
			foreach($result as $key=>$value){
				$type_list=$this->get_db_universal_type(17,1,NULL,NULL,$value['cid']);
				$result[$key]['cname']=$type_list['name2'];	
				$where_d['cid']=$value['cid'];
				$where_d['u_id']=$u_id;
				$where_d['type']=3;
				$result_d=$db_jixiao_pbc->where($where_d)->select();
				foreach($result_d as $kk=>$vv){
					$where_u['m_id']=$vv['id'];
					$where_u['status']=1;
					$result_u=$db_jixiao_pbc_user->where($where_u)->find();
					if($result_u){
						$result_d[$kk]['t1']=$result_u['t1'];
						$result_d[$kk]['t2']=$result_u['t2'];
						$result_d[$kk]['t3']=$result_u['t3'];
						$result_d[$kk]['c_value']=$result_u['c_value'];
						$result_d[$kk]['score']=$result_u['score'];
						if($vv['cid']!=5){
							$sum_w+=$vv['weight'];
						}
						$sum_t1+=$result_u['t1'];
						$sum_t2+=$result_u['t2'];
						$sum_t3+=$result_u['t3'];
						$sum_c_value+=$result_u['c_value'];
						$sum_score+=$result_u['score'];
						$this->assign("out_uid",$result_u['out_uid']);
						$this->assign("out_name",$this->get_user($result_u['out_uid']));
						$this->assign("ht_sdate",$result_u['ht_sdate']);
						$this->assign("ht_edate",$result_u['ht_edate']);
						$this->assign("qy_date",$result_u['qy_date']);
					}else{
						unset($result);
					}
				}
				if($result){
					$result[$key]['detail']=$result_d;
					$result[$key]['sum']=count($result_d);
				}
			}
		}
		$this->assign("sum_w",$sum_w?$sum_w:NULL);
		$this->assign("sum_t1",$sum_t1?$sum_t1:NULL);
		$this->assign("sum_t2",$sum_t2?$sum_t2:NULL);
		$this->assign("sum_t3",$sum_t3?$sum_t3:NULL);
		$this->assign("sum_c_value",$sum_c_value?$sum_c_value:NULL);
		$this->assign("sum_score",$sum_score?$sum_score:NULL);
		$this->assign("result",$result);
		$this->display();
	}
	
	//PBC管理 designed by:zhangsen 2018-03-08
	function jixiao_pbc_ajax(){
		$db_jixiao_pbc=M('db_jixiao_pbc');
		$db_jixiao_pbc_user=M('db_jixiao_pbc_user');
		$db_universal_type=M('db_universal_type');
		if($_REQUEST['action']=='data'){
			if($_REQUEST['p_id']){
				
			    $where['_string']="(cid='".$_REQUEST['cid']."' and type=1) or (p_id='".$_REQUEST['p_id']."' and cid='".$_REQUEST['cid']."')";
			}
			elseif($_REQUEST['u_id']){
				$where['_string']="(cid='".$_REQUEST['cid']."' and type=1) or (u_id='".$_REQUEST['u_id']."' and cid='".$_REQUEST['cid']."')";
			}
			else{
				$where['cid']=$_REQUEST['cid'];
				$where['type']=1;
			}
			$result=$db_jixiao_pbc->where($where)->group('name')->select();
		}elseif($_REQUEST['action']=='info'){
			$where['cid']=$_REQUEST['cid'];
			$where['name']=$_REQUEST['name'];
			$where['type']=1;
			$result=$db_jixiao_pbc->where($where)->find();
		}elseif($_REQUEST['action']=='add'){
			if($_REQUEST['p_id']){
				$where['p_id']=$_REQUEST['p_id'];
				$where['type']=2;
				//判断是否重复添加
				$where_c['p_id']=$_REQUEST['p_id'];
				$where_c['cid']=$_REQUEST['cid'];
				$where_c['name']=$_REQUEST['name'];
				$where_c['type']=2;
				$result_c=$db_jixiao_pbc->where($where_c)->find();
				if($result_c){
					$result['status']=self::NO;
					$result['msg']="不能重复添加指标";
					echo json_encode($result);die;
				}
			}
			elseif($_REQUEST['u_id']){
				$where['u_id']=$_REQUEST['u_id'];
				$where['type']=3;
				//判断是否重复添加
				$where_c['u_id']=$_REQUEST['u_id'];
				$where_c['cid']=$_REQUEST['cid'];
				if($_REQUEST['kpi_input']){
					$where_c['name']=$_REQUEST['kpi_input'];
				}else{
					$where_c['name']=$_REQUEST['name'];
				}
				$where_c['type']=3;
				$result_c=$db_jixiao_pbc->where($where_c)->find();
				if($result_c){
					$result['status']=self::NO;
					$result['msg']="不能重复添加指标";
					echo json_encode($result);die;
				}
				//添加职位数据到人员
				$where_z['u_id']=$_REQUEST['u_id'];
				$where_z['type']=3;
				$result_z=$db_jixiao_pbc->where($where_z)->group('cid')->select();
				if(empty($result_z)){
					$where_ad['u_id']=$_REQUEST['u_id'];
					if($_REQUEST['zb_input']){
						$where_s['type']=17;
						$result_f=$db_universal_type->where($where_s)->order('name1 desc')->find();
						$where_a['type']=17;
						$where_a['name1']=$result_f['name1']+1;
						$where_a['name2']=$_REQUEST['zb_input'];
						$db_universal_type->add($where_a);
						$where_ad['cid']=$result_f['name1']+1;
					}else{
						$where_ad['cid']=$_REQUEST['cid'];
					}
					if($_REQUEST['kpi_input']){
						$where_ad['name']=$_REQUEST['kpi_input'];
					}else{
						$where_ad['name']=$_REQUEST['name'];
					}
					$where_ad['unit']=$_REQUEST['unit']?$_REQUEST['unit']:NULL;
					$where_ad['weight']=$_REQUEST['weight'];
					$where_ad['cycle']=$_REQUEST['cycle'];
					$where_ad['type']=3;
					$where_ad['add_uid']=$this->login_id;
					$where_ad['add_date']=date('Y-m-d H:i:s');
					$db_jixiao_pbc->add($where_ad);
					$user=$this->get_user($_REQUEST['u_id']);
					$where_p['p_id']=$user['position_id'];
					$where_p['type']=2;
					$result_z=$db_jixiao_pbc->where($where_p)->group('cid')->select();
					foreach($result_z as $key=>$value){
						$where_d['cid']=$value['cid'];
						$where_d['p_id']=$user['position_id'];
						$where_d['type']=2;
						$result_d=$db_jixiao_pbc->where($where_d)->order('add_date asc,id asc')->select();
						foreach($result_d as $kk=>$vv){
							$where_add['u_id']=$_REQUEST['u_id'];
							$where_add['cid']=$vv['cid'];
							$where_add['name']=$vv['name'];
							$where_add['unit']=$vv['unit'];
							$where_add['weight']=$vv['weight'];
							$where_add['cycle']=$vv['cycle'];
							$where_add['type']=3;
							$where_add['add_uid']=$this->login_id;
							$where_add['add_date']=date('Y-m-d H:i:s');
							$db_jixiao_pbc->add($where_add);
						}
					}
					$result['status']=self::YES;
					echo json_encode($result);die;
				}
			}else{
				$where['type']=1;
			}
			if($_REQUEST['zb_input']){
				$where_s['type']=17;
				$result_f=$db_universal_type->where($where_s)->order('name1 desc')->find();
				$where_a['type']=17;
				$where_a['name1']=$result_f['name1']+1;
				$where_a['name2']=$_REQUEST['zb_input'];
				$db_universal_type->add($where_a);
				$where['cid']=$result_f['name1']+1;
			}else{
				$where['cid']=$_REQUEST['cid'];
			}
			if($_REQUEST['kpi_input']){
				$where['name']=$_REQUEST['kpi_input'];
			}else{
				$where['name']=$_REQUEST['name'];
			}
			$where['unit']=$_REQUEST['unit']?$_REQUEST['unit']:NULL;
			$where['weight']=$_REQUEST['weight'];
			$where['cycle']=$_REQUEST['cycle'];
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_jixiao_pbc->add($where);
			if($result_bool){
				$result['status']=self::YES;
			}
		}elseif($_REQUEST['action']=='edit'){
			$where['id']=$_REQUEST['id'];
			if($_REQUEST['p_id']){
				$where['p_id']=$_REQUEST['p_id'];
				$where['type']=2;
				//判断是否重复添加
				$where_c['p_id']=$_REQUEST['p_id'];
				$where_c['cid']=$_REQUEST['cid'];
				$where_c['name']=$_REQUEST['name'];
				$where_c['type']=3;
				$where_c['id']=array('neq',$_REQUEST['id']);
				$result_c=$db_jixiao_pbc->where($where_c)->find();
				if($result_c){
					$result['status']=self::NO;
					$result['msg']="不能重复添加指标";
					echo json_encode($result);die;
				}
			}
			elseif($_REQUEST['u_id']){
				$where['u_id']=$_REQUEST['u_id'];
				$where['type']=3;
				//判断是否重复添加
				$where_c['u_id']=$_REQUEST['u_id'];
				$where_c['cid']=$_REQUEST['cid'];
				if($_REQUEST['kpi_input']){
					$where_c['name']=$_REQUEST['kpi_input'];
				}else{
					$where_c['name']=$_REQUEST['name'];
				}
				$where_c['type']=3;
				$where_c['id']=array('neq',$_REQUEST['id']);
				$result_c=$db_jixiao_pbc->where($where_c)->find();
				if($result_c){
					$result['status']=self::NO;
					$result['msg']="不能重复添加指标";
					echo json_encode($result);die;
				}
				//添加职位数据到人员
				$where_z['u_id']=$_REQUEST['u_id'];
				$where_z['type']=3;
				$result_z=$db_jixiao_pbc->where($where_z)->group('cid')->select();
				if(empty($result_z)){
					if($_REQUEST['zb_input']){
						$where_s['type']=17;
						$result_f=$db_universal_type->where($where_s)->order('name1 desc')->find();
						$where_a['type']=17;
						$where_a['name1']=$result_f['name1']+1;
						$where_a['name2']=$_REQUEST['zb_input'];
						$db_universal_type->add($where_a);
						$where_ad['cid']=$result_f['name1']+1;
					}else{
						$where_ad['cid']=$_REQUEST['cid'];
					}
					if($_REQUEST['kpi_input']){
						$where_ad['name']=$_REQUEST['kpi_input'];
					}else{
						$where_ad['name']=$_REQUEST['name'];
					}
					$where_ad['u_id']=$_REQUEST['u_id'];
					$where_ad['unit']=$_REQUEST['unit']?$_REQUEST['unit']:NULL;
					$where_ad['weight']=$_REQUEST['weight'];
					$where_ad['cycle']=$_REQUEST['cycle'];
					$where_ad['type']=3;
					$where_ad['add_uid']=$this->login_id;
					$where_ad['add_date']=date('Y-m-d H:i:s');
					$db_jixiao_pbc->add($where_ad);
					$user=$this->get_user($_REQUEST['u_id']);
					$where_p['p_id']=$user['position_id'];
					$where_p['type']=2;
					$result_z=$db_jixiao_pbc->where($where_p)->group('cid')->select();
					foreach($result_z as $key=>$value){
						$where_d['cid']=$value['cid'];
						$where_d['p_id']=$user['position_id'];
						$where_d['type']=2;
						$result_d=$db_jixiao_pbc->where($where_d)->order('add_date asc,id asc')->select();
						foreach($result_d as $kk=>$vv){
							if($vv['id']!=$_REQUEST['id']){
								$where_add['u_id']=$_REQUEST['u_id'];
								$where_add['cid']=$vv['cid'];
								$where_add['name']=$vv['name'];
								$where_add['unit']=$vv['unit'];
								$where_add['weight']=$vv['weight'];
								$where_add['cycle']=$vv['cycle'];
								$where_add['type']=3;
								$where_add['add_uid']=$this->login_id;
								$where_add['add_date']=date('Y-m-d H:i:s');
								$db_jixiao_pbc->add($where_add);
							}
						}
					}
					$result['status']=self::YES;
					echo json_encode($result);die;
				}
			}else{
				$where['type']=1;
			}
			if($_REQUEST['zb_input']){
				$where_s['type']=17;
				$result_f=$db_universal_type->where($where_s)->order('name1 desc')->find();
				$where_a['type']=17;
				$where_a['name1']=$result_f['name1']+1;
				$where_a['name2']=$_REQUEST['zb_input'];
				$db_universal_type->add($where_a);
				$where['cid']=$result_f['name1']+1;
			}else{
				$where['cid']=$_REQUEST['cid'];
			}
			if($_REQUEST['kpi_input']){
				$where['name']=$_REQUEST['kpi_input'];
			}else{
				$where['name']=$_REQUEST['name'];
			}
			$where['unit']=$_REQUEST['unit']?$_REQUEST['unit']:NULL;
			$where['weight']=$_REQUEST['weight'];
			$where['cycle']=$_REQUEST['cycle'];
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_jixiao_pbc->save($where);
			if($result_bool){
				$result['status']=self::YES;
			}
		}elseif($_REQUEST['action']=='delete'){
			$where['id']=$_REQUEST['id'];
			$db_jixiao_pbc->where($where)->delete();
			$result['status']=self::YES;
		}elseif($_REQUEST['action']=='do_user'){
			$where_d['u_id']=$_REQUEST['u_id'];
			$db_jixiao_pbc_user->where($where_d)->delete();
			foreach($_REQUEST['m_id'] as $kk=>$vv){
				$where['u_id']=$_REQUEST['u_id'];
				$where['m_id']=$_REQUEST['m_id'][$kk];
				$where['out_uid']=$_REQUEST['out_uid'];
				$where['ht_sdate']=$_REQUEST['ht_sdate'];
				$where['ht_edate']=$_REQUEST['ht_edate'];
				$where['qy_date']=$_REQUEST['qy_date'];
				$where['t1']=$_REQUEST['t1'][$kk]?$_REQUEST['t1'][$kk]:NULL;
				$where['t2']=$_REQUEST['t2'][$kk]?$_REQUEST['t2'][$kk]:NULL;
				$where['t3']=$_REQUEST['t3'][$kk]?$_REQUEST['t3'][$kk]:NULL;
				$where['c_value']=$_REQUEST['c_value'][$kk]?$_REQUEST['c_value'][$kk]:NULL;
				$where['score']=$_REQUEST['score'][$kk]?$_REQUEST['score'][$kk]:NULL;
				$where['status']=1;
				$db_jixiao_pbc_user->add($where);
			}
			$result['status']=self::YES;
		}elseif($_REQUEST['action']=='give_user'){
			$where['u_id']=$_REQUEST['u_id'];
			$where_save['status']=-1;
			$db_jixiao_pbc_user->where($where)->save($where_save);
			$result['status']=self::YES;
		}elseif($_REQUEST['action']=='sync'){
			if($_REQUEST['p_id']){
				$where['p_id']=$_REQUEST['p_id'];
				$where['type']=2;
				$result=$db_jixiao_pbc->where($where)->select();
				foreach($result as $key=>$value){
					$where_f['name']=$value['name'];
					$where_f['type']=1;
					$result_f=$db_jixiao_pbc->where($where_f)->find();
					if($result_f){
						$where_d['id']=$result_f['id'];
						$db_jixiao_pbc->where($where_d)->delete();
					}
					$where_a['cid']=$value['cid'];
					$where_a['name']=$value['name'];
					$where_a['unit']=$value['unit']?$value['unit']:NULL;
					$where_a['weight']=$value['weight'];
					$where_a['cycle']=$value['cycle'];
					$where_a['type']=1;
					$where_a['add_uid']=$this->login_id;
					$where_a['add_date']=date('Y-m-d H:i:s');
					$result_bool=$db_jixiao_pbc->add($where_a);
				}
			}elseif($_REQUEST['u_id']){
				$where['u_id']=$_REQUEST['u_id'];
				$where['type']=3;
				$result=$db_jixiao_pbc->where($where)->select();
				foreach($result as $key=>$value){
					$where_f['name']=$value['name'];
					$where_f['type']=1;
					$result_f=$db_jixiao_pbc->where($where_f)->find();
					if($result_f){
						$where_d['id']=$result_f['id'];
						$db_jixiao_pbc->where($where_d)->delete();
					}
					$where_a['cid']=$value['cid'];
					$where_a['name']=$value['name'];
					$where_a['unit']=$value['unit']?$value['unit']:NULL;
					$where_a['weight']=$value['weight'];
					$where_a['cycle']=$value['cycle'];
					$where_a['type']=1;
					$where_a['add_uid']=$this->login_id;
					$where_a['add_date']=date('Y-m-d H:i:s');
					$result_bool=$db_jixiao_pbc->add($where_a);
				}
			}
			$result['status']=self::YES;
		}elseif($_REQUEST['action']=='position'){
			if($_REQUEST['pid'] && $_REQUEST['npid']){
				$where_d['p_id']=$_REQUEST['npid'];
				$db_jixiao_pbc->where($where_d)->delete();
				$where['p_id']=$_REQUEST['pid'];
				$where['type']=2;
				$result=$db_jixiao_pbc->where($where)->select();
				foreach($result as $key=>$value){
					$where_a['cid']=$value['cid'];
					$where_a['p_id']=$_REQUEST['npid'];
					$where_a['name']=$value['name'];
					$where_a['unit']=$value['unit']?$value['unit']:NULL;
					$where_a['weight']=$value['weight'];
					$where_a['cycle']=$value['cycle'];
					$where_a['type']=2;
					$where_a['add_uid']=$this->login_id;
					$where_a['add_date']=date('Y-m-d H:i:s');
					$result_bool=$db_jixiao_pbc->add($where_a);
				}
			}
			$result['status']=self::YES;
			$result['msg']='操作成功';
		}
		echo json_encode($result);die;
	}
	
	//人员需求管理 designed by:zhangsen 2018-03-08
	function person_demand(){
		parent::check_permission('XQ');
		$db_person_demand=M('db_person_demand');
		if(get_permission('XQ',3)){
			$where['db_audit_main.add_uid']=$this->login_id;
		}
		$where['db_audit_main.type']=7;
		$count=$db_person_demand->join('db_audit_main on db_person_demand.id=db_audit_main.audit_id')->where($where)->count();
		$Page=new \Think\Page($count,C('PAGE_LIST_ROWS')); 
		$show=$Page->show();
		$result=$db_person_demand->field('db_audit_main.*,db_audit_main.id as tid,db_person_demand.*')->join('db_audit_main on db_person_demand.id=db_audit_main.audit_id')->where($where)->order('add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($result as $key=>$value){
			$relationship=$this->user_list_ajax_relationship(1,$value['add_uid']);
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['report_user']=$this->get_username($value['report_uid']);
			$department=$this->get_oa_dep_info($value['department']);
			$result[$key]['department_name']=$department['HPS_DEPT_FULLDESCR'];
			$db_user=M('db_user');
			$where_p['position_id']=$value['position'];
			$result_user=$db_user->where($where_p)->find();
			$result[$key]['position_user']=$value['position_new']?$value['position_new']:$result_user['position_descr'];
			//审核流程
			if($value['status']==1){
				$result[$key]['audit_user']=$relationship['audit_user'];
			}else{
				$audit_user=$this->audit_type_next(7,$value['audit_type'],$value['status']);
				$result[$key]['audit_user']=$audit_user['audit_user'];
			}
			$result[$key]['dh_user']=$this->get_username($value['dh_uid']);
			
			//审核人员
			$audit_arr=$this->audit_user(7,$value['audit_type']);
			foreach($audit_arr as $kk=>$vv){
				if($value['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '人力资源审批':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit2_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit2_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit2_message'];
						break;
						case 'CHO审批':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit3_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit3_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit3_message'];
						break;
						case '公司领导审批':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit4_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit4_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit4_message'];
						break;
						case '人力资源部存档':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit5_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit5_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit5_message'];
						break;
					}
				}
				if(empty($vv['audit_uid']) and empty($audit_arr[$kk]['audit_user'])){unset($audit_arr[$kk]);}
			}
			if($relationship['audit_uid']){
			//判断审核人是否离职
			$judge_user1_user=$this->get_user($relationship['audit_uid']);
				if($judge_user1_user['status']!=1)
				{
					$relationship['audit_user']=$relationship['audit_user'].'(离职)';
				}
			}else{
				$relationship['audit_user']='无审核人';
			}
			$array1=array("audit_name"=>"用人部门审批","audit_user"=>"".$relationship['audit_user']."","audit_date"=>"".$value['audit1_date']."","audit_comments"=>"".$value['audit1_message']."","audit_sort"=>"1");
			array_unshift($audit_arr,$array1);
			$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($value['post_uid'])."","audit_date"=>"".$value['post_date']."","audit_sort"=>"-1");
			array_unshift($audit_arr,$array2);
			foreach($audit_arr as $k1=>$v1){
				if($value['arrive_status']==$v1['audit_sort']){
					$arrive_name=$v1['audit_name'];
					if($value['arrive_status']=='-1'){$arrive_info=$value['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
					$arrive_date=$v1['audit_date'];
				}
				if($value['dh_status']==$v1['audit_sort']){
					$audit_arr[$k1]['arrive_name']=$arrive_name;
					$audit_arr[$k1]['dh_message']=$value['dh_message'];
					$audit_arr[$k1]['dh_date']=$value['dh_date'];
					$audit_arr[$k1]['arrive_info']=$arrive_info;
					$audit_arr[$k1]['arrive_date']=$arrive_date;
				}
			}
			$result[$key]['audit_arr']=$audit_arr;
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//人员需求管理-->添加 designed by:zhangsen 2018-03-08
	function person_demand_add(){
		parent::check_permission('XQ');
		if($_REQUEST['action']=="add")
		{
			$db_person_demand=M('db_person_demand');
			if($_REQUEST['position_new']){
				$where['position_new']=$_REQUEST['position_new'];
			}else{
				$where['position']=$_REQUEST['position'];
			}
			$where['number']=$_REQUEST['number'];
			$where['rank']=$_REQUEST['rank'];
			$where['report_uid']=$_REQUEST['report_uid'];
			$where['department']=$_REQUEST['department'];
			$where['is_position']=$_REQUEST['is_position'];
			$where['sq_date']=$_REQUEST['sq_date'];
			$where['sq_remark']=$_REQUEST['sq_remark'];
			$where['reason1']=$_REQUEST['reason1']?$_REQUEST['reason1']:NULL;
			$where['reason2']=$_REQUEST['reason2']?$_REQUEST['reason2']:NULL;
			$where['reason3']=$_REQUEST['reason3']?$_REQUEST['reason3']:NULL;
			$where['reason4']=$_REQUEST['reason4']?$_REQUEST['reason4']:NULL;
			$where['reason5']=$_REQUEST['reason5']?$_REQUEST['reason5']:NULL;
			$where['requir1']=$_REQUEST['requir1']?$_REQUEST['requir1']:NULL;
			$where['requir2']=$_REQUEST['requir2']?$_REQUEST['requir2']:NULL;
			$where['requir3']=$_REQUEST['requir3']?$_REQUEST['requir3']:NULL;
			$where['requir4']=$_REQUEST['requir4']?$_REQUEST['requir4']:NULL;
			$where['requir5']=$_REQUEST['requir5']?$_REQUEST['requir5']:NULL;
			$where['file1']=$_REQUEST['file1']?$_REQUEST['file1']:NULL;
			$where['file2']=$_REQUEST['file2']?$_REQUEST['file2']:NULL;
			$where['file3']=$_REQUEST['file3']?$_REQUEST['file3']:NULL;
			if(!empty($_REQUEST['file_name1'])){$where['file_name1']=$_REQUEST['file_name1'];}
			if(!empty($_REQUEST['file_url1'])){$where['file_url1']=$_REQUEST['file_url1'];}
			if(!empty($_REQUEST['file_name2'])){$where['file_name2']=$_REQUEST['file_name2'];}
			if(!empty($_REQUEST['file_url2'])){$where['file_url2']=$_REQUEST['file_url2'];}
			if(!empty($_REQUEST['file_name3'])){$where['file_name3']=$_REQUEST['file_name3'];}
			if(!empty($_REQUEST['file_url3'])){$where['file_url3']=$_REQUEST['file_url3'];}
			$audit_id=$db_person_demand->add($where);
			//添加
			$db_audit_main=M('db_audit_main');
			$where_j_n['order_number']=array('like','XQ'.date('Ymd').'%');
			$judge_num=$db_audit_main->field('order_number')->where($where_j_n)->order('id desc')->select();
			if(empty($judge_num))
			{
				$num='001';
			}
			else
			{
				$num=substr($judge_num[0]['order_number'],10,3)+1;
				if(strlen($num)==1){$num='00'.$num;}
				elseif(strlen($num)==2){$num='0'.$num;}
			}
			$where_a['order_number']='XQ'.date('Ymd').$num;
			$where_a['audit_id']=$audit_id;
			$where_a['audit_type']=-10;
			$where_a['status']=-1;
			$where_a['type']=7;
			$where_a['add_uid']=$this->login_id;
			$where_a['add_date']=date('Y-m-d H:i:s');
			$db_audit_main->add($where_a);
			$this->success("操作成功",__APP__."/Hr/person_demand");die;
		}
		//姓名下拉菜单
		$this->assign('result1',$this->get_all_username(1));
		$user=$this->get_user($this->login_id);
		if($user['center_id']){
			//职位下拉
			$db_user=M('db_user');
			$where_4['center_id']=$user['center_id'];
			$where_4['position_descr']=array('exp','IS NOT NULL');
			$result_position=$db_user->field('position_id,position_descr')->where($where_4)->group('position_id')->order('position_id')->select();
			$this->assign('result_position',$result_position);
			//部门下拉
			$db_department=M('db_department');
			$where_dep['_string']="DEPTID =".$user['center_id']." or PART_DEPTID_CHN=".$user['center_id']." or PART_DEPTID_CHN in (SELECT DEPTID from db_department where PART_DEPTID_CHN=".$user['center_id'].")";
			$result_department=$db_department->where($where_dep)->select();
			$this->assign('result_department',$result_department);
		}
		$this->display();
	}
	
	//人员需求管理-->编辑 designed by:zhangsen 2018-03-08
	function person_demand_edit(){
		parent::check_permission('XQ');
		//详情
		$db_person_demand=M('db_person_demand');
		$where_r['db_person_demand.id']=$_REQUEST['id'];
		$where_r['db_audit_main.type']=7;
		$result=$db_person_demand->field('db_person_demand.*,db_audit_main.add_uid')->join('db_audit_main on db_person_demand.id=db_audit_main.audit_id')->where($where_r)->find();
		$this->assign('result',$result);
		//姓名下拉菜单
		$this->assign('result1',$this->get_all_username(1));
		$user=$this->get_user($result['add_uid']);
		if($user['center_id']){
			//职位下拉
			$db_user=M('db_user');
			$where_4['center_id']=$user['center_id'];
			$where_4['position_descr']=array('exp','IS NOT NULL');
			$result_position=$db_user->field('position_id,position_descr')->where($where_4)->group('position_id')->order('position_id')->select();
			$this->assign('result_position',$result_position);
			$db_department=M('db_department');
			$where_dep['_string']="DEPTID =".$user['center_id']." or PART_DEPTID_CHN=".$user['center_id']." or PART_DEPTID_CHN in (SELECT DEPTID from db_department where PART_DEPTID_CHN=".$user['center_id'].")";
			$result_department=$db_department->where($where_dep)->select();
			$this->assign('result_department',$result_department);
		}
		if($_REQUEST['action']=="edit")
		{
			$where_save['id']=$_REQUEST['id'];
			if($_REQUEST['position_new']){
				$where_save['position_new']=$_REQUEST['position_new'];
				$where_save['position']=NULL;
			}else{
				$where_save['position']=$_REQUEST['position'];
				$where_save['position_new']=NULL;
			}
			$where_save['number']=$_REQUEST['number'];
			$where_save['rank']=$_REQUEST['rank'];
			$where_save['report_uid']=$_REQUEST['report_uid'];
			$where_save['department']=$_REQUEST['department'];
			$where_save['is_position']=$_REQUEST['is_position'];
			$where_save['sq_date']=$_REQUEST['sq_date'];
			$where_save['sq_remark']=$_REQUEST['sq_remark'];
			$where_save['reason1']=$_REQUEST['reason1']?$_REQUEST['reason1']:NULL;
			$where_save['reason2']=$_REQUEST['reason2']?$_REQUEST['reason2']:NULL;
			$where_save['reason3']=$_REQUEST['reason3']?$_REQUEST['reason3']:NULL;
			$where_save['reason4']=$_REQUEST['reason4']?$_REQUEST['reason4']:NULL;
			$where_save['reason5']=$_REQUEST['reason5']?$_REQUEST['reason5']:NULL;
			$where_save['requir1']=$_REQUEST['requir1']?$_REQUEST['requir1']:NULL;
			$where_save['requir2']=$_REQUEST['requir2']?$_REQUEST['requir2']:NULL;
			$where_save['requir3']=$_REQUEST['requir3']?$_REQUEST['requir3']:NULL;
			$where_save['requir4']=$_REQUEST['requir4']?$_REQUEST['requir4']:NULL;
			$where_save['requir5']=$_REQUEST['requir5']?$_REQUEST['requir5']:NULL;
			$where_save['file1']=$_REQUEST['file1']?$_REQUEST['file1']:NULL;
			$where_save['file2']=$_REQUEST['file2']?$_REQUEST['file2']:NULL;
			$where_save['file3']=$_REQUEST['file3']?$_REQUEST['file3']:NULL;
			if(!empty($_REQUEST['file_name1'])){
				$where_save['file_name1']=$_REQUEST['file_name1'];
				if($_REQUEST['file_url1']){
					//判断是否修改过文件
					if($_REQUEST['file_url1']!=$result_d['file_url1']){
						$where_save['file_url1']=$_REQUEST['file_url1'];
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url1']);
						if (file_exists($file1)){
							@unlink($file1);
						}
					}
				}else{
					$where_save['file_url1']=NULL;
					if($result_d['file_url1']){
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url1']);
						if(file_exists($file1)){
							@unlink($file1);
						}
					}
				}
			}else{
				$where_save['file_name1']=NULL;
				$where_save['file_url1']=NULL;
				if($result_d['file_url1']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url1']);
					if(file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			if(!empty($_REQUEST['file_name2'])){
				$where_save['file_name2']=$_REQUEST['file_name2'];
				if($_REQUEST['file_url2']){
					//判断是否修改过文件
					if($_REQUEST['file_url2']!=$result_d['file_url2']){
						$where_save['file_url2']=$_REQUEST['file_url2'];
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url2']);
						if (file_exists($file1)){
							@unlink($file1);
						}
					}
				}else{
					$where_save['file_url2']=NULL;
					if($result_d['file_url2']){
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url2']);
						if(file_exists($file1)){
							@unlink($file1);
						}
					}
				}
			}else{
				$where_save['file_name2']=NULL;
				$where_save['file_url2']=NULL;
				if($result_d['file_url2']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url2']);
					if(file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			if(!empty($_REQUEST['file_name3'])){
				$where_save['file_name3']=$_REQUEST['file_name3'];
				if($_REQUEST['file_url3']){
					//判断是否修改过文件
					if($_REQUEST['file_url3']!=$result_d['file_url3']){
						$where_save['file_url3']=$_REQUEST['file_url3'];
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url3']);
						if (file_exists($file1)){
							@unlink($file1);
						}
					}
				}else{
					$where_save['file_url3']=NULL;
					if($result_d['file_url3']){
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url3']);
						if(file_exists($file1)){
							@unlink($file1);
						}
					}
				}
			}else{
				$where_save['file_name3']=NULL;
				$where_save['file_url3']=NULL;
				if($result_d['file_url3']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url3']);
					if(file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			$db_person_demand->save($where_save);
			$this->success("操作成功",__APP__."/Hr/person_demand/&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//人员需求管理-->详情 designed by:zhangsen 2018-03-08
	function person_demand_detail(){
		$db_person_demand=M('db_person_demand');
		$where['db_person_demand.id']=$_REQUEST['id'];
		$where['db_audit_main.type']=7;
		$result=$db_person_demand->field('db_person_demand.*,db_audit_main.*,db_person_demand.id as tid')->join('db_audit_main on db_person_demand.id=db_audit_main.audit_id')->where($where)->find();
		$result['add_user']=$this->get_username($result['add_uid']);
		$result['report_user']=$this->get_username($result['report_uid']);
		$department=$this->get_oa_dep_info($result['department']);
		$result['department_name']=$department['HPS_DEPT_FULLDESCR'];
		$db_user=M('db_user');
		$where_p['position_id']=$result['position'];
		$result_user=$db_user->where($where_p)->find();
		$result['position_user']=$result['position_new']?$result['position_new']:$result_user['position_descr'];
		$result['dh_user']=$this->get_username($result['dh_uid']);
		$user=$this->get_user($result['add_uid']);
		$result['sq_position_user']=$user['position_descr'];
		$department=$this->get_oa_dep_info($user['department_id']);
		$result['sq_department_name']=$department['HPS_DEPT_FULLDESCR'];
		//审核人员
		$audit_arr=$this->audit_user(7,$result['audit_type']);
		foreach($audit_arr as $kk=>$vv){
			if($result['status']>$vv['audit_sort']){
				switch($vv['audit_name']){
					case '人力资源审批':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit2_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit2_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit2_message'];
					break;
					case 'CHO审批':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit3_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit3_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit3_message'];
					break;
					case '公司领导审批':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit4_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit4_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit4_message'];
					break;
					case '人力资源部存档':
						$audit_arr[$kk]['audit_user']=$this->get_username($result['audit5_uid']);
						$audit_arr[$kk]['audit_date']=$result['audit5_date'];
						$audit_arr[$kk]['audit_comments']=$result['audit5_message'];
					break;
				}
			}
			if(empty($vv['audit_uid']) and empty($audit_arr[$kk]['audit_user'])){unset($audit_arr[$kk]);}
		}
		//判断审核人是否离职
		$relationship=$this->user_list_ajax_relationship(1,$result['add_uid']);
		if($relationship['audit_uid']){
			//判断审核人是否离职
			$judge_user1_user=$this->get_user($relationship['audit_uid']);
			if($judge_user1_user['status']!=1)
			{
				$relationship['audit_user']=$relationship['audit_user'].'(离职)';
			}
		}else{
			$relationship['audit_user']='无审核人';
		}
		
		$array1=array("audit_name"=>"用人部门审批","audit_user"=>"".$relationship['audit_user']."","audit_date"=>"".$result['audit1_date']."","audit_comments"=>"".$result['audit1_message']."","audit_sort"=>"1");
		array_unshift($audit_arr,$array1);
		$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($result['post_uid'])."","audit_date"=>"".$result['post_date']."","audit_sort"=>"-1");
		array_unshift($audit_arr,$array2);
		foreach($audit_arr as $k1=>$v1){
			if($result['arrive_status']==$v1['audit_sort']){
				$arrive_name=$v1['audit_name'];
				if($result['arrive_status']=='-1'){$arrive_info=$result['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
				$arrive_date=$v1['audit_date'];
			}
			if($result['dh_status']==$v1['audit_sort']){
				$audit_arr[$k1]['arrive_name']=$arrive_name;
				$audit_arr[$k1]['dh_message']=$result['dh_message'];
				$audit_arr[$k1]['dh_date']=$result['dh_date'];
				$audit_arr[$k1]['arrive_info']=$arrive_info;
				$audit_arr[$k1]['arrive_date']=$arrive_date;
			}
		}
		$this->assign('audit_user',$audit_arr);
		foreach($audit_arr as $ka=>$va){
			if($result['status']<=$va['audit_sort']){
				unset($audit_arr[$ka]);
			}
		}
		$this->assign('audit_list',$audit_arr);
		$audit_sh=$this->audit_type_next_person(7,$result['audit_type'],$result['status'],'egt');
		$audit_qs=$this->audit_type_next_person(7,$result['audit_type'],$result['status'],'lt');
		if($result['status']==1){
			if($relationship['audit_uid']==$this->login_id){
				$shenhe=1;
			}
		}else{
			if($result['status']!=-1){
				if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
			}
		}
		if($result['status']==2){
			if($relationship['audit_uid']==$this->login_id){
				$qishen=1;
			}
		}else{
			if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
		}
		$this->assign('shenhe',$shenhe);
		$this->assign('qishen',$qishen);
		$this->assign('result',$result);
		$this->assign('audit',$_REQUEST['audit']);
		$this->display();
	}
	
	//人员需求管理-->ajax操作 designed by:zhangsen 2018-03-08
	function person_demand_ajax(){
		$db_person_demand=M('db_person_demand');
		$db_audit_main=M('db_audit_main');
		if($_REQUEST['action']=='position'){
			$db_user=M('db_user');
			$where['position_id']=$_REQUEST['position_id'];
			$result_user=$db_user->where($where)->find();
			$db_department=M('db_department');
			$where_dep['_string']="DEPTID =".$result_user['center_id']." or PART_DEPTID_CHN=".$result_user['center_id']." or PART_DEPTID_CHN in (SELECT DEPTID from db_department where PART_DEPTID_CHN=".$result_user['center_id'].")";
			$result=$db_department->where($where_dep)->select();
		}elseif($_REQUEST['action']=='delete'){
			//删除审核流程单
			$where_s['audit_id']=$_REQUEST['id'];
			$where_s['type']=7;
			$db_audit_main->where($where_s)->delete();
			$where['id']=$_REQUEST['id'];
			$data['status']=$db_person_demand->where($where)->delete();
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		echo json_encode($result);die;
	}
	
	//【系统】定时自动更新-->更新用户基本信息(每天的02:30:00) designed by:zhangsen 2018-03-28
    //定时任务减一天改为昨天的23点30 addby liubao 2018年8月21日
	function system_timing_update_dep(){
		$date=$_REQUEST['date']?$_REQUEST['date']:date('Y-m-d',strtotime("-3 hour"));
		$oa_dep=$this->get_oa_dep($date,date('Y-m-d H:i:s'));
		preg_match_all("/\<MsgData\>(.*?)\<\/MsgData\>/s",$oa_dep,$xmlstring);
		$xml = simplexml_load_string($xmlstring[0][0]);
		$oa_dep= json_decode(json_encode($xml),TRUE);
		$dep_oa=$oa_dep['Transaction']['HPS_IF_MSG_WRK']['HPS_HRIFDEP_OA'];
		if(!empty($dep_oa['DEPTID'])){
			$dep_arr[0]=$dep_oa;
		}else{
			$dep_arr=$dep_oa;
		}
        $this->add_log('debug同步部门模块',$dep_arr);
		$db_department=M('db_department');
		foreach($dep_arr as $key=>$value){
			if($value['DEPTID']){
				//判断是否重复
				$where_c['DEPTID']=$value['DEPTID'];
				$result_c=$db_department->where($where_c)->find();
				if($result_c){
					$where_s['DEPTID']=$value['DEPTID'];
					$where_edit['DEPT_DESCR']=$value['DEPT_DESCR'];
					$where_edit['HPS_DEPT_FULLDESCR']=$value['HPS_DEPT_FULLDESCR'];
					$where_edit['HPS_DEPT_CLASS']=$value['HPS_DEPT_CLASS'];
					$where_edit['DESCR']=$value['DESCR'];
					$where_edit['PART_DEPTID_CHN']=$value['PART_DEPTID_CHN'];
					$where_edit['DESCR1']=$value['DESCR1'];
					$where_edit['EFF_STATUS']=$value['EFF_STATUS'];
					$where_edit['LASTUPDOPRID']=$value['LASTUPDOPRID'];
					$where_edit['LASTUPDDTTM']=$value['LASTUPDDTTM'];
					$db_department->where($where_s)->save($where_edit);
					$this->add_log('同步更新部门',$where_edit);
				}else{
					unset($where_add);
					$where_add['DEPTID']=$value['DEPTID'];
					$where_add['DEPT_DESCR']=$value['DEPT_DESCR'];
					$where_add['HPS_DEPT_FULLDESCR']=$value['HPS_DEPT_FULLDESCR'];
					$where_add['HPS_DEPT_CLASS']=$value['HPS_DEPT_CLASS'];
					$where_add['DESCR']=$value['DESCR'];
					$where_add['PART_DEPTID_CHN']=$value['PART_DEPTID_CHN'];
					$where_add['DESCR1']=$value['DESCR1'];
					$where_add['EFF_STATUS']=$value['EFF_STATUS'];
					$where_add['LASTUPDOPRID']=$value['LASTUPDOPRID'];
					$where_add['LASTUPDDTTM']=$value['LASTUPDDTTM'];
					$db_department->add($where_add);
                    $this->add_log('同步新增部门',$where_add);
				}
			}
		}
		$data['status']=self::YES;
		$data['msg']='操作成功';
		echo json_encode($data);die;
	}
	
	//【系统】定时自动更新-->更新用户基本信息(每天的02:40:00) designed by:zhangsen 2018-03-28
    //定时任务减一天改为昨天的23点40 addby liubao 2018年8月21日
	function system_timing_update_user(){
		$date=$_REQUEST['date']?$_REQUEST['date']:date('Y-m-d',strtotime("-3 hour"));
		$oa_user=$this->get_oa_user($date,date('Y-m-d H:i:s'));
		preg_match_all("/\<MsgData\>(.*?)\<\/MsgData\>/s",$oa_user,$xmlstring);
		$xml = simplexml_load_string($xmlstring[0][0]);
		$oa_user= json_decode(json_encode($xml),TRUE);
		$user_oa=$oa_user['Transaction']['HPS_IF_MSG_WRK']['HPS_HRIFEMP_OA'];
		if(!empty($user_oa['EMPLID'])){
			$user_arr[0]=$user_oa;
		}else{
			$user_arr=$user_oa;
		}
        $this->add_log('debug同步用户模块',$user_arr);
		$i=0;
		foreach($user_arr as $key=>$value){
			if(!empty($value['EMPLID'])){
				$db_user=M('db_user');
				$where_e['empl_id']=$value['EMPLID'];
				$result_e=$db_user->where($where_e)->find();
				if(empty($result_e)){
					$where_add['empl_id']=$value['EMPLID'];
					$where_add['username']=$value['NAME'];
					$spell_array=explode('@',$value['EMAIL_ADDR']);
					$where_add['spell']=$spell_array[0];
					$where_add['regname']=$value['EMPLID'];
					$where_add['password']=111111;
					$where_add['user_number']=$value['HPS_ORI_EMPLID'];
					$where_add['mobilephone']=$value['PHONE'];
					$where_add['email']=$value['EMAIL_ADDR'];
					if($value['HR_STATUS']=='A'){$where_add['status']=1;}
					else{$where_add['status']=-1;$where_add['disable_date']=$value['LASTUPDDTTM'];}
					$dep=$this->get_oa_dep_next($value['DEPTID']);
					$where_add['center_id']=$dep['DEPTID']?$dep['DEPTID']:-1;
					$where_add['center_descr']=$dep['DEPT_DESCR']?$dep['DEPT_DESCR']:'集团';
					$where_add['department_id']=$value['DEPTID'];
					$where_add['position_id']=$value['POSITION_NBR'];
					$where_add['position_descr']=$value['POSN_DESCR'];
					$where_add['rank_id']=$value['HPS_POSN_LVL'];
					$where_add['rank_descr']=$value['HPS_DESCR2'];
					$where_add['permissions_id']='8,10';
					$where_add['update_date']=$value['LASTUPDDTTM'];
					$where_add['add_date']=$value['LASTUPDDTTM'];
					$db_user->add($where_add);
                    $this->do_pro_user($where_e,'add');
                    $this->add_log('同步新增用户',$where_add);
					$i++;
				}else{
					if(empty($value['NATIONAL_ID'])){
						$where_g['empl_id']=$value['EMPLID'];
						$where_save_g['status']=-1;
						$where_save_g['disable_date']=$value['LASTUPDDTTM'];
						$where_save_g['update_date']=$value['LASTUPDDTTM'];
						$bool=$db_user->where($where_g)->save($where_save_g);
					}else{
						$where_w['empl_id']=$value['EMPLID'];
						unset($where_save['username1']);
						if($result_e['username']!=$value['NAME']){
							$where_save['username1']=$value['NAME'];
						}
						$spell_array=explode('@',$value['EMAIL_ADDR']);
						$where_save['spell']=$spell_array[0];
						$where_save['user_number']=$value['HPS_ORI_EMPLID'];
						$where_save['mobilephone']=$value['PHONE'];
						$where_save['email']=$value['EMAIL_ADDR'];
						if($value['HR_STATUS']=='A'){$where_save['status']=1;}
						else{$where_save['status']=-1;$where_save['disable_date']=$value['LASTUPDDTTM'];}
						$dep=$this->get_oa_dep_next($value['DEPTID']);
						$where_save['center_id']=$dep['DEPTID']?$dep['DEPTID']:-1;
						$where_save['center_descr']=$dep['DEPT_DESCR']?$dep['DEPT_DESCR']:'集团';
						$where_save['department_id']=$value['DEPTID'];
						$where_save['position_id']=$value['POSITION_NBR'];
						$where_save['position_descr']=$value['POSN_DESCR'];
						$where_save['rank_id']=$value['HPS_POSN_LVL'];
						$where_save['rank_descr']=$value['HPS_DESCR2'];
						$where_save['update_date']=$value['LASTUPDDTTM'];
						$bool=$db_user->where($where_w)->save($where_save);
						$this->do_pro_user($where_w,'update');
                        $this->add_log('同步更新用户',$where_save);
					}
					if($bool){$i++;}
				}
			}
		}
		$data['status']=self::YES;
		$data['msg']='操作成功,更新'.$i.'条数据';
		echo json_encode($data);die;
	}
	function system_timing_update_user1(){
		$db_user=M('db_user');
		$db_user_new=M('db_user_new');
		$user_oa=$db_user_new->where($where)->select();
		foreach($user_oa as $key=>$value){
			$where_e['username']=$value['username'];
			$result_e=$db_user->where($where_e)->find();
			if(empty($result_e)){
				$where_add['empl_id']=$value['empl_id'];
				$where_add['username']=$value['username'];
				$where_add['password']=111111;
				$where_add['mobilephone']=$value['mobilephone'];
				$where_add['email']=$value['email'];
				$where_add['user_number']=$value['user_number'];
				$dep=$this->get_oa_dep_next($value['department_id']);
				$where_add['center_id']=$dep['DEPTID'];
				$where_add['center_descr']=$dep['DEPT_DESCR'];
				$where_add['department_id']=$value['department_id'];
				$where_add['position_id']=$value['position_id'];
				$where_add['position_descr']=$value['position_descr'];
				$where_add['rank_id']=$value['rank_id'];
				$where_add['rank_descr']=$value['rank_descr'];
				$where_add['permissions_id']='8,10';
				$where_add['add_date']=$value['add_date'];
				$db_user->add($where_add);
			}else{
				$where_w['username']=$value['username'];
				$where_save['empl_id']=$value['empl_id'];
				$where_save['mobilephone']=$value['mobilephone'];
				$where_save['user_number']=$value['user_number'];
				$where_save['email']=$value['email'];
				$dep=$this->get_oa_dep_next($value['department_id']);
				$where_save['center_id']=$dep['DEPTID'];
				$where_save['center_descr']=$dep['DEPT_DESCR'];
				$where_save['department_id']=$value['department_id'];
				$where_save['position_id']=$value['position_id'];
				$where_save['position_descr']=$value['position_descr'];
				$where_save['rank_id']=$value['rank_id'];
				$where_save['rank_descr']=$value['rank_descr'];
				$db_user->where($where_w)->save($where_save);
			}
		}
		$data['status']=self::YES;
		$data['msg']='操作成功';
	}
	function system_timing_update_dep1(){
		$db_department=M('db_department');
		$dep_oa=$db_department->select();
		$str="";
		foreach($dep_oa as $key=>$value){
			if($value['PART_DEPTID_CHN']=='130001'){
				$str="景域目的地运营集团-".$value['DEPT_DESCR'];
			}else{
				$where_a['DEPTID']=$value['PART_DEPTID_CHN'];
				$dep_oa_a=$db_department->where($where_a)->find();
				if($dep_oa_a['PART_DEPTID_CHN']=="130001"){
					$str="景域目的地运营集团-".$dep_oa_a['DEPT_DESCR']."-".$value['DEPT_DESCR'];
				}else{
					$where_b['DEPTID']=$dep_oa_a['PART_DEPTID_CHN'];
					$dep_oa_b=$db_department->where($where_b)->find();
					if($dep_oa_b['PART_DEPTID_CHN']=="130001"){
						$str="景域目的地运营集团-".$dep_oa_b['DEPT_DESCR']."-".$dep_oa_a['DEPT_DESCR']."-".$value['DEPT_DESCR'];
					}else{
						$str="景域国际旅游运营集团-".$value['DEPT_DESCR'];
					}
				}
			}
			
			$where_w['DEPTID']=$value['DEPTID'];
			$where_save['HPS_DEPT_FULLDESCR']=$str;
			$db_department->where($where_w)->save($where_save);
		}
	}

	/*//更新部门长描述为空的信息
    function update_all()
    {
        $db_department = M("db_department");
        $db_all = M("db_all");
        $DEPTIDs = $db_department->field("DEPTID")->where("HPS_DEPT_FULLDESCR is NULL")->select();
        $DEPTID = '';
        foreach ($DEPTIDs as $k=>$v){
            $DEPTID[] = $v['DEPTID'];
        }
        $DEPTID = implode(',',$DEPTID);
        $all = $db_all->where("DEPTID in ($DEPTID)")->field("DEPTID,HPS_DEPT_FULLDESCR")->select();
        $Model = new \Think\Model();
        foreach ($all as $k=>$v){
            $deptid = $v['DEPTID'];
            $HPS_DEPT_FULLDESCR = $v['HPS_DEPT_FULLDESCR'];
            $Model->execute("update db_department set HPS_DEPT_FULLDESCR='$HPS_DEPT_FULLDESCR' where DEPTID=$deptid");
        }
    }

    //录入缺失组织架构的信息
    public function addDepartment()
    {
        $db_all = M("db_all");
        $db_department = M("db_department");
        $deptIds = $db_department->field("DEPTID")->select();
        $deptId = '';
        foreach ($deptIds as $k=>$v){
            $deptId[] = $v['DEPTID'];
        }
        $deptId = implode(',',$deptId);
        $not_in_all = $db_all->where("DEPTID not in ($deptId)")->select();
        foreach ($not_in_all as $key=>$value){
            $where_add['DEPTID']=$value['DEPTID'];
            $where_add['DEPT_DESCR']=$value['DEPT_DESCR'];
            $where_add['HPS_DEPT_FULLDESCR']=$value['HPS_DEPT_FULLDESCR'];
            $where_add['HPS_DEPT_CLASS']=$value['HPS_DEPT_CLASS'];
            $where_add['DESCR']=$value['DESCR'];
            $where_add['PART_DEPTID_CHN']=$value['PART_DEPTID_CHN'];
            $where_add['DESCR1']=$value['DESCR1'];
            $where_add['EFF_STATUS']=$value['EFF_STATUS'];
            $where_add['LASTUPDOPRID']=$value['LASTUPDOPRID'];
            $where_add['LASTUPDDTTM']=$this->do_date($value['LASTUPDDTTM']);
            $db_department->add($where_add);
        }
    }


    public function do_date($date)
    {
        //$date = '28-5月 -18 07.53.53.000000 下午';
        $day = substr($date,'0','2');
        $mouth = substr($date, strlen('-')+strpos($date, '-'),(strlen($date) - strpos($date, '月'))*(-1));
        if ($mouth<10){
            $mouth = '0'.$mouth;
        }
        $year_weizhi = strrpos($date,' -');
        $year = substr($date,$year_weizhi+2,'2');
        $year='20'.$year;
        $i_and_s = substr($date,'-19','5');
        $h = substr($date,'-22','2');
        if (substr($date,'-6','6') == '下午'){
            $h = $h+12;
        };
        $i_and_s = str_replace('.',':',$i_and_s);
        $time =$year.'-'.$mouth.'-'.$day.' '.$h.':'.$i_and_s;
        return $time;
    }*/
}
?>